//
//  MBScanPreviewViewController.m
//  MemberBusiness-ios
//
//  Created by 掌心 on 2018/6/1.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBScanPreviewViewController.h"
#import "MBOrderPayViewController.h"

@interface MBScanPreviewViewController ()

@end

@implementation MBScanPreviewViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
 
    [self setupLayout];
}

-(void)setupLayout
{
    [super setupLayout];
    self.naviView.titleLabel.text = @"照片";
    [self.naviView setUpBackButton];
    
    UIButton* rightButton = [[UIButton alloc]init];
    [rightButton addTarget:self action:@selector(handleClickRightItem) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setTitle:@"完成" forState:UIControlStateNormal];
    rightButton.titleLabel.font = [UIFont lf_regularFontOfSize:15];
    [self.naviView addSubview:rightButton];
    
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.naviView.titleLabel);
        make.right.equalTo(self.naviView).offset([UIView lf_sizeFromIphone6:-13]);
    }];
    
    @weakify(self);
    [[self.naviView.backButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    UIImageView* imageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    imageView.image = self.scanImage;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imageView];

}

-(void)handleClickRightItem
{
//    // 创建一个CIImage对象
//    CIImage *ciImage = [[CIImage alloc] initWithCGImage:self.scanImage.CGImage options:nil];
//    CIContext *context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 软件渲染
//    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 二维码识别
//    // 注意这里的CIDetectorTypeQRCode
//    NSArray *features = [detector featuresInImage:ciImage];
//    NSLog(@"features = %@",features); // 识别后的结果集
//    for (CIQRCodeFeature *feature in features) {
//        NSLog(@"msg = %@",feature.messageString); // 打印二维码中的信息
//    }
    MBOrderPayViewController * orderPayVC = [[MBOrderPayViewController alloc]initWithViewModel:[[MBOrderPayViewModel alloc]init] ];
    [self.navigationController pushViewController:orderPayVC animated:YES];
}

@end
